all files / popup/ popup.vue

19.35% Statements 6/31
22.22% Branches 4/18
11.11% Functions 1/9
9.09% Lines 2/22
1 branch Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79                      1×                                                                                                                                      
//
//
//
//
//
//
//
//
//
//
 
import Popup from '../internal/popup'
export default {
  name: 'mu-popup',
  mixins: [Popup],
  props: {
    popupClass: {
      type: [String, Object, Array]
    },
    popupTransition: {
      type: String,
      default: ''
    },
    position: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      transition: this.popupTransition
    }
  },
  created () {
    if (!this.popupTransition) {
      this.transition = `popup-slide-${this.position}`
    }
  },
  computed: {
    popupCss () {
      const {position, popupClass} = this
      let classNames = []
      if (position) classNames.push('mu-popup-' + position)
      if (!popupClass) return classNames
      if (popupClass instanceof Object) {
        for (const name in popupClass) {
          if (popupClass[name]) classNames.push(name)
        }
      } else if (popupClass instanceof Array) {
        classNames = classNames.concat(popupClass)
      } else {
        classNames = classNames.join(' ') + ' ' + popupClass
      }
      return classNames
    }
  },
  methods: {
    overlayClick () {
      this.$emit('close', 'overlay')
    },
    escPress () {
      this.$emit('close', 'esc')
    },
    show () {
      this.$emit('show')
    },
    hide () {
      this.$emit('hide')
    }
  },
  watch: {
    popupTransition (val, oldVal) {
      if (val === oldVal) return
      this.transition = val
    }
  }
}